﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace BlogDH.Ajax
{
    /// <summary>
    /// GetArea 的摘要说明
    /// </summary>
    public class GetArea : IHttpHandler
    {

        public void ProcessRequest(HttpContext context)
        {
            context.Response.ContentType = "text/plain";

            string sql = string.Empty;
            string json = "";

            string typeinfo = context.Request.QueryString["type"];
            int areaid = int.Parse(context.Request.QueryString["id"]);

            //直辖市判断
            if (typeinfo == "shi" && (areaid == 11 || areaid == 12 || areaid == 31 || areaid == 50))
            { sql = "pid=0 and areaid=" + areaid; }
            else
            { sql = " pid=" + areaid; }
            System.Data.DataSet ds = new BLL.Area().GetList(sql);
            List<object> list = new List<object>();

            for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
            {
                var item = new { id = ds.Tables[0].Rows[i]["areaid"], name = ds.Tables[0].Rows[i]["name"] };
                list.Add(item);
            }
            json = Lib.Utils.JsonHelper.ToJson(list);

            context.Response.Write(json);
        }

        public bool IsReusable
        {
            get
            {
                return false;
            }
        }
    }
}